﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//using Model;

/// <summary>
/// Description résumée de ZoneManager
/// </summary>
/// 
namespace DAL
{
    public class ZoneManager : IZoneManager
    {
        private IAATOEntities dbService;

        public ZoneManager()
        {
            dbService = new IAATOEntities();
        }

        public bool addZone(ZONE zone)
        {
            try
            {
                dbService.ZONEJeu.AddObject(zone);
                dbService.SaveChanges();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public bool deleteZone(int zoneId)
        {
            try
            {
                ZONE zone = (from z in dbService.ZONEJeu
                             where z.ID == zoneId
                             select z).First();

                dbService.DeleteObject(zone);
                dbService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }

        }

        public List<ZONE> getAllZones()
        {
            try
            {
                return (from z in dbService.ZONEJeu
                        orderby z.NOM
                        select z).ToList();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public bool updateZone()
        {
            try
            {
                dbService.SaveChanges();
                return true;
            }

            catch (Exception ex)
            {
                return false;
            }
        }

        public ZONE getZoneById(int id)
        {
            try
            {
                return (from z in dbService.ZONEJeu
                        where z.ID == id
                        select z).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public string getNom(int id)
        {
            try
            {
                return (from z in dbService.ZONEJeu
                        where z.ID == id
                        select z.NOM).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public ZONE getZoneByNom(string nom)
        {
            try
            {
                return (from z in dbService.ZONEJeu
                        where z.NOM == nom
                        select z).First();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}